﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.Unitity;
using Microsoft.Xna.Framework;

namespace Spinning.Spinning.Entity.Battle
{
    class FakeBattlePlayer : AnimationSprite
    {
        public int Style { get; set; }

        public enum SpinningMoveType
        {
            Forward, StayMeddle, GoBack
        }

        public SpinningMoveType CurrentSpinningType
        {
            get;
            set;
        }

        public void AttackMessage(string str)
        {
            MovableTextEntity addText = new MovableTextEntity();
            ResourceManager.ContentRoot = "";
            addText.fontString = "CenturyGothicBold";
            addText.OnLoad();
            addText.Origin = new Vector2(0.5f);
            addText.Position = new Vector2(0, -10);
            addText.Color = Color.Green;
            addText.ZIndex = Constants.debugText;
            addText.Static = false;
            Attach(addText);
            addText.Time = 1;
            addText.Path = new Vector2(0, -30);
            if (!str.Contains("B"))
            {
                if (Math.Abs(Convert.ToInt32(str)) < 5)
                {
                    isFlash = true;
                }
            }
            if (str == "Block!")
            {
                addText.Color = Color.Black;
            }
            else if (str.Contains("-"))
            {
                addText.Color = Color.Red;
            }
            addText.Value = str;
        }

        public FakeBattlePlayer() 
        {
            CurrentSpinningType = SpinningMoveType.StayMeddle;
        }


        public bool isFlash = false;
        int tempTimerFlash, flashCounter = 0;
        protected override void UpdateSelf(Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.UpdateSelf(gameTime);
            int delta = gameTime.ElapsedGameTime.Milliseconds;

            if (CurrentSpinningType == SpinningMoveType.Forward)
            {
                SetChangeFrameAnimation(new int[] { 4 + Style * 6, 5 + Style * 6 });
            }
            else if (CurrentSpinningType == SpinningMoveType.GoBack)
            {
                SetChangeFrameAnimation(new int[] { 2 + Style * 6, 3 + Style * 6 });
            }
            else
            {
                SetChangeFrameAnimation(new int[] { 0 + Style * 6, 1 + Style * 6 });
            }

            if (isFlash)
            {
                Alpha = Math.Abs((float)Math.Sin(tempTimerFlash));
                tempTimerFlash += delta;
                if (tempTimerFlash / 300 > 1)
                {
                    tempTimerFlash = tempTimerFlash % 300;
                    flashCounter++;
                    if (flashCounter == 1)
                    {
                        flashCounter = 0;
                        isFlash = false;
                        Alpha = 1;
                    }
                }
            }
        }
    }
}
